# -*- coding: UTF-8 -*-
# @Time : 2021-01-01 19:08
# @File : log.py
import logging
import time
import os
from config import Conf

# 1、设置logger名称
logger = logging.getLogger('log_file_demo')
# 2、设置logger级别
logger.setLevel(logging.DEBUG)
# 3、创建控制台handler
fh_stream = logging.StreamHandler()
# 4、写入文件日志
fh_file = logging.FileHandler(Conf.get_config_logs() + os.sep + time.strftime("%Y-%m-%d", time.localtime()) + '.log')
# 5、设置日志级别
fh_stream.setLevel(logging.DEBUG)
# 输出日志级别
fh_file.setLevel(logging.DEBUG)
# 6、定义输出格式
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s ')
fh_stream.setFormatter(formatter)
fh_file.setFormatter(formatter)
# 7、添加handler
logger.addHandler(fh_stream)
logger.addHandler(fh_file)
logger.info('info')
logger.debug('debug')
logger.warning('warning')
logger.error('error')